class Solution
{
public:
    int minimumPossibleSum(int n, int target)
    {
        long long halfTarget = target / 2;
        long long nn = n;
        if (halfTarget >= nn)
        {
            return (nn * (nn + 1) / 2) % 1'0000'0000'7;
        }
        long long remain = nn - halfTarget;
        return (halfTarget * (halfTarget + 1) / 2 + (2 * target + remain - 1) * remain / 2) % 1'0000'0000'7;
    }
};